﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CNotebook;
using CNotebook.Inventory;

namespace NotebookS2.Inventory.Logs
{
    public partial class LOGS_IGE : Form
    {
        public LOGS_IGE()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }

        public void PrintPreview()
        {
            if (xtraTabControl1.SelectedTabPageIndex == 0)
            {
                if (!gridControlDocuments.IsPrintingAvailable)
                {
                    MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error");
                    return;
                }
                gridControlDocuments.ShowPrintPreview();
                
            }
            else
            {
                if (!gridControlItems.IsPrintingAvailable)
                {
                    MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error");
                    return;
                }
                
                gridControlItems.ShowPrintPreview();
            }
        }

        private void btnPreviewItems_Click(object sender, EventArgs e)
        {
            try
            {
                IssueManager oManager = new IssueManager();

                oManager.ConnectionString = this.ConnectionString;
                oManager.Open();

                DataTable _table = oManager.GetTransactionLogPerItem((DateTime)dtFROMItems.EditValue, (DateTime)dtTOItems.EditValue);

                oManager.Close();

                gridControlItems.DataSource = _table;
                gridControlItems.Refresh();
                gridViewItems.ExpandAllGroups();
            }
            catch
            {
            }
        }

        private void LOGS_IGE_Load(object sender, EventArgs e)
        {
            dtFromDocuments.EditValue = System.DateTime.Now;
            dtTODocuments.EditValue = System.DateTime.Now;

            dtTOItems.EditValue = System.DateTime.Now;
            dtFROMItems.EditValue = System.DateTime.Now;
        }

        private void btnRetreiveDocuments_Click(object sender, EventArgs e)
        {
            try
            {
                IssueManager oManager = new IssueManager();

                oManager.ConnectionString = this.ConnectionString;
                oManager.Open();

                DataTable _table = oManager.GetTransactionLogPerDocument((DateTime)dtFromDocuments.EditValue, (DateTime)dtTODocuments.EditValue);

                oManager.Close();

                gridControlDocuments.DataSource = _table;
                gridControlDocuments.Refresh();
                gridViewDocuments.ExpandAllGroups();
            }
            catch
            {
            }
        }
    }
}
